 package handling.channel.handler;

 import client.MapleCharacter;
import client.MapleClient;
import client.MapleProcess;
import com.alibaba.druid.pool.DruidPooledConnection;
import database.DatabaseConnection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.Timer;
import server.console.groups.datamanage.PlayerPane;
import tools.data.input.LittleEndianAccessor;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;























 public class SystemProcess
 {
/*  28 */   public static final Map<String, String> WG_Property = new HashMap<>();
/*  29 */   private static final Logger log = LogManager.getLogger(SystemProcess.class.getName());

   public static void SystemProcess(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/*  32 */     int num = slea.readShort();



/*  36 */     String svchost = slea.readMapleAsciiString();



     try {
/*  41 */       for (int i = 0; i < num; i++) {
/*  42 */         slea.readInt();
/*  43 */         String cMD5 = slea.readMapleAsciiString();

/*  45 */         String path = slea.readMapleAsciiString();



/*  49 */         PlayerPane.getInstance().printProcessList("路径->" + path);
/*  50 */         MapleProcess process = new MapleProcess(path, cMD5);
/*  51 */         if (checkWGProcess(process) != null || checkWGProcess(chr.getProcess()) != null) {

/*  53 */           if (checkWGProcess(process) != null) {
/*  54 */             MapleProcess WG = checkWGProcess(process);
           } else {
/*  56 */             MapleProcess WG = checkWGProcess(chr.getProcess());
           }

/*  59 */           chr.dropMessage(1, "检测到非法程序!");
/*  60 */           Timer.CheatTimer.getInstance().schedule(() -> {  },10000L);
         }


/*  64 */         boolean loged = false;
/*  65 */         List<MapleProcess> temp = chr.getProcess();
/*  66 */         for (MapleProcess mp : temp) {
/*  67 */           if (mp.getPath().equals(path) && mp.getMD5().equals(cMD5)) {
/*  68 */             loged = true;
             break;
           }
         }
/*  72 */         if (!loged) {
/*  73 */           chr.getProcess().add(process);
         }
       }
/*  76 */     } catch (Exception e) {
/*  77 */       log.error(e);
     }
/*  79 */     chr.setLastCheckProcess(System.currentTimeMillis());
   }

   public static void loadWGProperty() {
/*  83 */     WG_Property.clear();
/*  84 */     try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection(); 
/*  85 */         PreparedStatement ps = con.prepareStatement("SELECT * FROM hacker")) {
/*  86 */       try (ResultSet rs = ps.executeQuery()) {
/*  87 */         while (rs.next()) {
/*  88 */           WG_Property.put(rs.getString("name"), rs.getString("md5").toLowerCase());
         }
       }
/*  91 */       ps.close();
     }
/*  93 */     catch (SQLException e) {
/*  94 */       System.err.println("獲取外掛特征時出現問題：" + e);
     }
   }

   public static MapleProcess checkWGProcess(List<MapleProcess> processList) {
/*  99 */     if (WG_Property.isEmpty()) {
/* 100 */       loadWGProperty();
     }
/* 102 */     for (MapleProcess process : processList) {
/* 103 */       if (WG_Property.containsValue(process.getMD5().toLowerCase()) || WG_Property.containsKey(process.getName())) {
/* 104 */         return process;
       }
     }
/* 107 */     return null;
   }

   public static MapleProcess checkWGProcess(MapleProcess process) {
/* 111 */     if (WG_Property.isEmpty()) {
/* 112 */       loadWGProperty();
     }
/* 114 */     if (WG_Property.containsValue(process.getMD5().toLowerCase()) || WG_Property.containsKey(process.getName())) {
/* 115 */       return process;
     }
/* 117 */     return null;
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\SystemProcess.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */